package algorithm.sort;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ShellSort {

    private static final Logger logger = LoggerFactory.getLogger(ShellSort.class);

    @Test
    public void test() {
        int[] arr = {0, 4, 3, 1, 2, 6, 5};
        sort(arr);
        for (int i : arr) {
            logger.info(String.valueOf(i));
        }
    }

    // 三层for循环
    public void sort(int[] arr) {
        int num;
        // temp 为增量
        for (int temp = arr.length / 2; temp > 0; temp = temp / 2) {
            for (int i = temp; i < arr.length; i++) {
                // 增量的数据互相比较交换位置
                for (int j = i; j >= temp; j = j - temp) {
                    if (arr[j] < arr[j - temp]) {
                        num = arr[j - temp];
                        arr[j - temp] = arr[j];
                        arr[j] = num;
                    }
                }
            }
        }
    }


}
